<?php
namespace Tbf\Bundle\TestBundle\HttpTest;
use Tbf\Bundle\TbfBundle\DependencyInjection\TbfContainerAware;
use Tbf\Component\Http\Ajax;

class ServerSession {
    protected $ajax;
    function __construct(Ajax $ajax){
        $this->ajax = $ajax;
    }
    function setAll($data){
        $ret = $this->ajax->request(array(
            'url'=>'/tbf_test/sessionSetAllApi',
            'method'=>'POST',
            'data'=>array(
                'session'=>$data
            )
        ));
        if ($ret['err']!==null){
            throw new \Exception('err in ajax '.var_export($ret,true));
        }
    }
    function getAll(){
        $ret = $this->ajax->request(array(
            'url'=>'/tbf_test/sessionGetAllApi',
        ));
        if ($ret['err']!==null){
            throw new \Exception('err in ajax '.var_export($ret,true));
        }
        return $ret['data'];
    }
    function get($name){
        $data = $this->getAll();
        return $data[$name];
    }
    function set($name,$value){
        $ret = $this->ajax->request(array(
            'url'=>'/tbf_test/sessionSetApi',
            'method'=>'POST',
            'data'=>array(
                'name'=>$name,
                'value'=>$value
            )
        ));
        if ($ret['err']!==null){
            throw new \Exception('err in ajax '.var_export($ret,true));
        }
    }
}